package org.me.marble;

import android.view.*;
import android.widget.*;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.widget.TableLayout.LayoutParams;

public class DetailsActivity extends Activity {
	private DisplayMetrics dm;
	private SharedPreferences sd;
	
	@Override
	public void onCreate(Bundle icycle){
		super.onCreate(icycle);

		Display display=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		dm=new DisplayMetrics();
    	display.getMetrics(dm);
    	
		sd=getSharedPreferences(
				Context.ACTIVITY_SERVICE,Context.MODE_PRIVATE);
		    	
		setContentView(R.layout.details);
		TableLayout layout=(TableLayout)findViewById(R.details.maintable);
		
		for(int i=1;i<=OptionsLibrary.reached_level;++i)
			addRow(layout,i);
	}
	
	public void addRow(TableLayout table,int levelId){
		TextView level=new TextView(this);
		level.setTextSize(24);
		level.setPadding((int)(20*dm.density),0,0,0);
		level.setText(Integer.toString(levelId));
		
		TextView normal=new TextView(this);
		normal.setTextSize(24);
		normal.setPadding((int)(40*dm.density),0,0,0);
		normal.setText(Integer.toString(sd.getInt("level"+Integer.toString(levelId)+"_normal",0)));
		
		TextView point=new TextView(this);
		point.setTextSize(24);
		point.setPadding((int)(40*dm.density),0,0,0);
		point.setText(Integer.toString(sd.getInt("level"+Integer.toString(levelId)+"_point",0)));
		
		TextView time=new TextView(this);
		time.setTextSize(24);
		time.setPadding((int)(30*dm.density),0,0,0);
		time.setText(Float.toString(sd.getFloat("level"+Integer.toString(levelId)+"_time",0.0f))+" sec");
		
		TableRow row=new TableRow(this);
		row.addView(level);
		row.addView(normal);
		row.addView(point);
		row.addView(time);
		table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		
		TableRow divider=new TableRow(this);
		divider.setBackgroundColor(Color.GRAY);
		table.addView(divider,LayoutParams.FILL_PARENT,2);
	}
}
